#include <stdio.h>
int main(){
	int i,n,x;
	int flag = 1;
	scanf("%d",&n);
	int a[n+1];
	a[n] = 0;
	for(i = 0;i<n;i++){
		scanf("%d",&a[i]);
	}scanf("%d",&x);
	for(i = n-1;i>=0;i--){
		if(a[i]<x){
			for(int j = n;j>i+1;j--){
				a[j] = a[j-1];
			}a[i+1] = x;
			flag = 0;
			break;
		}
	}if(flag){
		for(i = n;i>0;i--){
			a[i] = a[i-1];
		}a[0] = x;
	}for(i = 0;i<n+1;i++){
		printf("%d",a[i]);printf(" ");
	}return 0;
}
